<template>
  <div class="app-wrapper" :class="theme">
    <!-- 水平布局头部 -->
    <header class="header-horizontal">
      <div class="logo" v-if="!logoHidden">
        <Logo></Logo>
      </div>
      <div class="nav-horizontal">
        <el-menu mode="horizontal" :default-active="activeMenu" @select="handleMenuSelect" unique-opened>
          <Menus :menu-list="menus" />
        </el-menu>
      </div>
      <div class="header-right">
        <Tools></Tools>
      </div>
    </header>

    <!-- 标签栏 -->
    <div class="tag-container" :class="{ 'dark-bg': theme === 'dark' }">
      <Tag />
    </div>

    <div class="container">
      <!-- 主内容区域 -->
      <main class="main-content">
        <router-view />
      </main>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useLayoutStore } from '@/store/layout'
import useUserStore from '@/store/modules/user.ts'
import Logo from '@/layouts/logo/index.vue'
import Tools from '@/layouts/header/tools.vue'
import Menus from '@/layouts/menus/index.vue'
import Tag from '@/layouts/tag/index.vue'
const router = useRouter()
const route = useRoute()
const layoutStore = useLayoutStore()
const userStore = useUserStore()

// 计算属性
const logoHidden = computed(() => layoutStore.layoutSettings.logoHidden)
const theme = computed(() => layoutStore.layoutSettings.theme)
const activeMenu = computed(() => route.path)
const menus = computed(() => userStore.userState.menus)

const handleMenuSelect = (key: string) => {
  router.push(key)
}


</script>

<style scoped lang="scss">
// 基础样式
.app-wrapper {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;

  // 水平布局头部
  .header-horizontal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: $header-height;
    padding: 0 20px;

    .nav-horizontal {
      flex: 1;
      margin-left: 20px;
    }

    .header-right {
      display: flex;
      align-items: center;
    }

    // 确保el-menu继承父元素背景色
    .el-menu {
      background-color: transparent;
    }

  }


  // 标签栏样式
  .tag-container {
    height: $tag-height;
    border-bottom: 1px solid $border-color;
    box-shadow: $box-shadow-light-header;
    
    &.dark-bg {
      border-bottom: 1px solid #333;
    }
  }
  
  // 主内容区域样式
  .main-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    height: calc(100vh - $header-height - $tag-height);
  }
}

// 响应式适配
@media screen and (max-width: 768px) {
  .main-content {
    padding: 10px;
  }
}
</style>